package com.twu.biblioteca.domain;

import java.util.ArrayList;
import java.util.List;

public class Library {

    private List<Book> books;
    private List<Movie> movies;

    public Library() {
        this.books = new ArrayList<Book>();
        this.movies = new ArrayList<Movie>();
    }

    public void reserveBook(String title) throws BookNotAvailableException {
        Book book = getBook(title);

        if (book == null || book.isReserved())
            throw new BookNotAvailableException();

        book.setReserved(true);
    }

    public Book getBook(String title) {
        title = title.toLowerCase();

        for (Book book : books) {
            if (book.getTitle().toLowerCase().equals(title))
                return book;
        }

        return null;
    }

    public List<Book> getBooks(){
        return this.books;
    }

    public List<Movie> getMovies(){
        return this.movies;
    }

    public void addBook(String title) {
        this.books.add(new Book(title));
    }

    public void addMovie(String title, int year, String director, int rating ){
        this.movies.add(new Movie(title, year, director, rating));
    }
}
